<?php

namespace backend\modules\pooai\models;

use Yii;
use yii\behaviors\TimestampBehavior;

/**
 * This is the model class for table "zpooai_gall_images".
 *
 * @property string $pooai_gall_images_id
 * @property string $zpooai_pages_id
 * @property string $zpooai_image
 * @property integer $sort_number
 */
class ZpooaiGallImages extends \yii\db\ActiveRecord
{
    public $images;

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'zpooai_gall_images';
    }

    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
//            TimestampBehavior::className(),
            // 名为myBehavior4的行为，也是给出了MyBehavior类的配置数组
            'uuid' => [
                'class' => \common\behavior\uuidBehavior::className(),
                'owner' => $this
            ]
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            ['pooai_gall_images_id','default','value'=>$this->getUUID()],
            [['pooai_gall_images_id'], 'required'],
            [['sort_number'], 'integer'],
            [['pooai_gall_images_id', 'zpooai_pages_id'], 'string', 'max' => 40],
            [['zpooai_image'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'pooai_gall_images_id' => Yii::t('app', 'Pooai Gall Images ID'),
            'zpooai_pages_id' => Yii::t('app', '官网页面'),
            'zpooai_image' => Yii::t('app', '官网图片'),
            'sort_number' => Yii::t('app', '图片排序'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getZpooaiPages()
    {
        return $this->hasOne(ZpooaiPages::className(), ['pooai_pages_id' => 'zpooai_pages_id']);
    }

    /**
     * @inheritdoc
     * @return \backend\modules\pooai\models\query\ZpooaiGallImagesQuery the active query used by this AR class.
     */
    public static function find()
    {
        return new \backend\modules\pooai\models\query\ZpooaiGallImagesQuery(get_called_class());
    }

    /**
     * 下拉数据数组
     *
     * zpooaiPagesAlias('all');
     * @param $type
     * @return array|\backend\modules\models\ZpooaiPages[]
     */
    public static function zpooaiPagesAlias($type)
    {
        $allFilter = array();
        if($type=="all"){
            $pooaiPages =  ZpooaiPages::find()->select(['pooai_pages_id','pooai_pages_name'])->asArray()->all();
        }
        foreach($pooaiPages as $k=>$v) {
            $allFilter[$v['pooai_pages_id']] = $v['pooai_pages_name'];
        }
        return $allFilter;
    }
}
